
package com.bstek.urule.model.rete;

import com.bstek.urule.model.Node;
import com.bstek.urule.model.library.ResourceLibrary;
import com.bstek.urule.runtime.rete.ObjectTypeActivity;
import com.bstek.urule.runtime.rete.ReteInstance;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Jacky.gao
 * @since 2015年1月6日
 */
public class Rete implements Node {
    private List<ObjectTypeNode> objectTypeNodes;
    private ResourceLibrary resourceLibrary;

    public Rete() {
    }

    public Rete(List<ObjectTypeNode> objectTypeNodes, ResourceLibrary resourceLibrary) {
        this.objectTypeNodes = objectTypeNodes;
        this.resourceLibrary = resourceLibrary;
    }

    public List<ObjectTypeNode> getObjectTypeNodes() {
        return objectTypeNodes;
    }

    public ResourceLibrary getResourceLibrary() {
        return resourceLibrary;
    }

    public ReteInstance newReteInstance() {
        List<ObjectTypeActivity> objectTypeActivities = new ArrayList<ObjectTypeActivity>();
        Map<Object, Object> contextMap = new HashMap<Object, Object>();
        for (ObjectTypeNode node : objectTypeNodes) {
            objectTypeActivities.add((ObjectTypeActivity) node.newActivity(contextMap));
        }
        return new ReteInstance(objectTypeActivities);
    }
}
